<template>
  <div class="form">
    <div class="stu">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="姓名" prop="StuName">
          <el-input v-model="ruleForm.StuName"></el-input>
        </el-form-item>
        <el-form-item label="学号" prop="StuId">
          <el-input v-model="ruleForm.StuId"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="StuPhone">
          <el-input v-model="ruleForm.StuPhone"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="StuSex">
          <el-select v-model="ruleForm.StuSex" placeholder="请选择性别">
            <el-option label="男" value="male"></el-option>
            <el-option label="女" value="female"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="StuAge">
          <el-input v-model="ruleForm.StuAge"></el-input>
        </el-form-item>
        <el-form-item label="入学时间" prop="StubackTime">
          <el-input v-model="ruleForm.StubackTime"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="StuEmail">
          <el-input v-model="ruleForm.StuEmail"></el-input>
        </el-form-item>
        <el-form-item label="班级" prop="StuClassId">
          <el-input v-model="ruleForm.StuClassId"></el-input>
        </el-form-item>
        <el-form-item label="年级" prop="Grade">
          <el-input v-model="ruleForm.Grade"></el-input>
        </el-form-item>
        <el-form-item label="政治面貌" prop="PoliticalLandscape ">
          <el-input v-model="ruleForm.PoliticalLandscape "></el-input>
        </el-form-item>
        <el-form-item label="籍贯" prop="NativePlace ">
          <el-input v-model="ruleForm.NativePlace "></el-input>
        </el-form-item>
        <el-form-item label="民族" prop="National ">
          <el-input v-model="ruleForm.National "></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交申请</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="tea">
      <el-form
        :model="ruleFormtea"
        :rules="rulestea"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="姓名" prop="WorkerName">
          <el-input v-model="ruleFormtea.WorkerName"></el-input>
        </el-form-item>
        <el-form-item label="工号" prop="WorkerId">
          <el-input v-model="ruleFormtea.WorkerId"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="WorkerPhone">
          <el-input v-model="ruleFormtea.WorkerPhone"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="WorkerSex">
          <el-select v-model="ruleFormtea.WorkerSex" placeholder="请选择性别">
            <el-option label="男" value="male"></el-option>
            <el-option label="女" value="female"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="WorkerAge">
          <el-input v-model="ruleFormtea.WorkerAge"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="StuEmail">
          <el-input v-model="ruleForm.StuEmail"></el-input>
        </el-form-item>
        <el-form-item label="班级" prop="StuClassId">
          <el-input v-model="ruleForm.StuClassId"></el-input>
        </el-form-item>
        <el-form-item label="年级" prop="Grade">
          <el-input v-model="ruleForm.Grade"></el-input>
        </el-form-item>
        <el-form-item label="政治面貌" prop="PoliticalLandscape ">
          <el-input v-model="ruleForm.PoliticalLandscape "></el-input>
        </el-form-item>
        <el-form-item label="籍贯" prop="NativePlace ">
          <el-input v-model="ruleForm.NativePlace "></el-input>
        </el-form-item>
        <el-form-item label="民族" prop="National ">
          <el-input v-model="ruleForm.National "></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交申请</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  props: ["status"],
  data() {
    return {
      ruleForm: {
        StuName: "",
        StuId: "",
        StuPhone: "",
        StuSex: "",
        StuAge: "",
        StubackTime: "",
        StuEmail: "",
        ClassId: "",
        Grade: "",
        StuCarid: "",
        ProfessionalName: "",
        StuCarid: "",
        NativePlace: "",
        National: ""
      },
      ruleFormtea: {
        StuName: "",
        StuId: "",
        StuPhone: "",
        StuSex: "",
        StuAge: "",
        StubackTime: "",
        StuEmail: "",
        ClassId: "",
        Grade: "",
        StuCarid: "",
        ProfessionalName: "",
        StuCarid: "",
        NativePlace: "",
        National: ""
      },
      rules: {
        StuName: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        StuId: [{ required: true, message: "请输入学号", trigger: "blur" }],
        StuPhone: [
          { required: true, message: "请输入手机号", trigger: "blur" }
        ],
        StuSex: [{ required: true, message: "请输入性别", trigger: "blur" }],
        StuAge: [
          { required: true, message: "请输入年龄", trigger: "blur" },
          { type: "number", message: "年龄必须为数字值" }
        ],
        StubackTime: [
          { required: true, message: "请输入入学时间", trigger: "blur" }
        ],
        StuEmail: [
          { required: true, message: "请输入电子邮件", trigger: "blur" }
        ],
        StuClassId: [
          { required: true, message: "请输入班级", trigger: "blur" }
        ],
        Grade: [{ required: true, message: "请输入年纪", trigger: "blur" }]
        //college: [{ required: true, message: "请输入学院", trigger: "blur" }]
      },
       rulestea: {
        StuName: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        StuId: [{ required: true, message: "请输入学号", trigger: "blur" }],
        StuPhone: [
          { required: true, message: "请输入手机号", trigger: "blur" }
        ],
        StuSex: [{ required: true, message: "请输入性别", trigger: "blur" }],
        StuAge: [
          { required: true, message: "请输入年龄", trigger: "blur" },
          { type: "number", message: "年龄必须为数字值" }
        ],
        StubackTime: [
          { required: true, message: "请输入入学时间", trigger: "blur" }
        ],
        StuEmail: [
          { required: true, message: "请输入电子邮件", trigger: "blur" }
        ],
        StuClassId: [
          { required: true, message: "请输入班级", trigger: "blur" }
        ],
        Grade: [{ required: true, message: "请输入年纪", trigger: "blur" }]
        //college: [{ required: true, message: "请输入学院", trigger: "blur" }]
      }
    };
  },
  created() {
    this.userInfo();
  },
  methods: {
    userInfo() {
      this.ruleForm = JSON.parse(sessionStorage.getItem("user"));
      var date = new Date(this.ruleForm.StubackTime);
      this.ruleForm.StubackTime =
        date.getFullYear() + "-" + date.getMonth() + "-" + date.getDay();
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          var date = new Date();
          var user = JSON.parse(sessionStorage.getItem("user"));
          var studentInfo = {
            id: 0,
            stuId: this.ruleForm.StuId,
            alterStuName: this.ruleForm.StuName,
            alterStuAge: this.ruleForm.StuAge,
            alterStuSex: this.ruleForm.StuSex,
            alterStuCarid: this.ruleForm.StuCarid,
            alterClassId: this.ruleForm.StuClassId,
            alterStubackTime: user.StubackTime,
            alterStuPhone: this.ruleForm.StuPhone,
            alterPoliticalLandscape: this.ruleForm.PoliticalLandscape,
            alterNativePlace: this.ruleForm.NativePlace,
            alterNational: this.ruleForm.National,
            workerId: this.ruleForm.TheCounselorId,
            alterStuStatus: 0,
            alterStuemail: this.ruleForm.StuEmail
          };
          console.log(JSON.stringify(studentInfo));
          this.$axios({
            method: "post",
            url: this.$api.InsertAlterStu,
            headers: {
              "Content-Type": "application/json"
            },
            data: JSON.stringify(studentInfo)
          }).then(res => {
            if (res.data.code == 200) {
              //sessionStorage.setItem("user",JSON.stringify(res.data.message))
              this.$message({
                message: "提交申请成功",
                type: "success"
              });
              this.$router.go(0);
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};
</script>

<style scoped>
.form {
  overflow-y: scroll;
  min-height: 400px;
  height: 450px;
  width: 100%;
}
</style>
